package chapter02.part07;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
 * 将输入按照匹配的分配符分开
 * 
 * @author insight
 * @since 2021/8/28
 */
public class DelimiterResult {
    public static void main(String[] args) throws IOException {
        // 使用 splits 获取分割后的数组
        String input = "1,2,3";
        Pattern commas = Pattern.compile("\\s*, \\s*");
        String[] tokens = commas.split(input);
        
        // 惰性获取
        Stream<String> tokensStream = commas.splitAsStream(input);
        
        // 不关心编译模式和惰性获取
        String[] rets = input.split("\\s*, \\s*");
        
        // 数据在文件
        Path dir = Paths.get("");
        Scanner in = new Scanner(dir, StandardCharsets.UTF_8);
        in.useDelimiter("\\s*, \\s*");
        Stream<String> retStream = in.tokens();
    }
}